﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ext.Net;

public partial class StoreManage : BasePage
{
    Bussiness.Store sm = new Bussiness.Store();
    protected void Page_Load(object sender, EventArgs e)
    {
        setContent();
    }


    private void setContent()
    {
        Store1.DataSource = sm.GetList("").Tables[0].DefaultView;
        Store1.DataBind();

    }

    protected void HandleChanges(object sender, BeforeStoreChangedEventArgs e)
    {
        ChangeRecords<Bussiness.Store> persons = e.DataHandler.ObjectData<Bussiness.Store>();

        foreach (Bussiness.Store created in persons.Created)
        {
            int tempId = created.id;
            sm.store = created.store;
            sm.Logo = created.Logo;
            sm.Returns = created.Returns;
            sm.Payment = created.Payment;
            sm.Replies = created.Replies;
            sm.Shipping = created.Shipping;
            sm.Feedback = created.Feedback;
            sm.FAQ = created.FAQ;
            int newId = sm.Add();

            if (Store1.UseIdConfirmation)
            {
                e.ConfirmationList.ConfirmRecord(tempId.ToString(), newId.ToString());
            }
            else
            {
                Store1.UpdateRecordId(tempId, newId);
            }

        }

        foreach (Bussiness.Store deleted in persons.Deleted)
        {
           // this.DeletePerson(deleted.id);
            sm.Delete(deleted.id);
            if (Store1.UseIdConfirmation)
            {
                e.ConfirmationList.ConfirmRecord(deleted.id.ToString());
            }
        }

        foreach (Bussiness.Store updated in persons.Updated)
        {
            //this.UpdatePerson(updated);
            sm.id = updated.id;
            sm.store = updated.store;
            sm.Logo = updated.Logo;
            sm.Returns = updated.Returns;
            sm.Payment = updated.Payment;
            sm.Replies = updated.Replies;
            sm.Shipping = updated.Shipping;
            sm.Feedback = updated.Feedback;
            sm.FAQ = updated.FAQ;
            sm.Update();
            if (Store1.UseIdConfirmation)
            {
                e.ConfirmationList.ConfirmRecord(updated.id.ToString());
            }
        }
        e.Cancel = true;
    }
}